/**
 * 
 */
package au.com.twosquared.animalfarm.entities;

import java.util.ArrayList;

import au.com.twosquared.animalfarm.map.Map;

import com.badlogic.gdx.graphics.g2d.SpriteBatch;

/**
 * 
 * Defines the functions to update and several entities within a list
 * 
 * @author Jan Martin <jan.martin@twosquared.com.au>
 * @version 1.0 2011-15-11
 * @since 2011-15-11
 * 
 */
@SuppressWarnings("serial")
public class EntityList extends ArrayList<Entity> {

	/**
	 * Updates a list of entities given the change in time
	 * 
	 * @param delta
	 *            the change in time
	 */
	public void update(long delta) {
		for (Entity e : this) {
			e.update(delta);
		}
	}

	/**
	 * Perform collision between the map AND all other entities
	 * 
	 * @param map
	 *            current map
	 */
	public void collision(Map map) {
		// The order of operations on this needs to be discussed
		for (Entity e : this) {
			for (Entity q : this) {
				if(q == e) continue;
				e.collision(q);
			}
			e.collision(map);
		}
	}
	
	/**
	 * Draws all the entities given a batch of sprites
	 * 
	 * @param batch
	 *            the batch of sprites
	 */
	public void draw(SpriteBatch batch) {
		for (Entity e : this) {
			e.draw(batch);
		}
	}

}
